/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "stub.h"
#include "NasReplicationService.h"
#include "HetroCommonService.h"

using ::testing::_;
using testing::AllOf;
using ::testing::AnyNumber;
using ::testing::AtLeast;
using testing::ByMove;
using testing::DoAll;
using ::testing::Eq;
using ::testing::Field;
using ::testing::Ge;
using ::testing::Gt;
using testing::InitGoogleMock;
using ::testing::Invoke;
using ::testing::Ne;
using ::testing::Return;
using ::testing::Sequence;
using ::testing::SetArgReferee;
using ::testing::SetArgumentPointee;
using ::testing::Throw;
using namespace NasRepServiceObjOp;
using namespace std;
using namespace Module;

class NasReplicationServiceTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    static void SetUpTestCase();
    static void TearDownTestCase();
    std::shared_ptr<DoradoNas> m_localController;
    std::unique_ptr<NasRepServiceObjOp::NasReplicationService> m_nasReplicationServiceObj;
    Stub stub;
};

static int BatchQueryRemoteDeviceFail_Stub(void* obj)
{
    return Module::FAILED;
}

static int BatchQueryRemoteDeviceSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static bool WaitRemoteDeviceNormalMethodSuc_Stub(void* obj)
{
    return true;
}

static bool WaitRemoteDeviceNormalMethodFail_Stub(void* obj)
{
    return false;
}

static bool CreateResourceSuc_Stub(void* obj)
{
    return true;
}

static bool CreateResourceFail_Stub(void* obj)
{
    return false;
}

static bool ReturnFalse_Stub(void* obj)
{
    return false;
}

static bool ReturnTrue_Stub(void* obj)
{
    return true;
}

static void returnVoid_Stub(void* obj)
{
    return;
}

static bool QueryResourceSuc_Stub(void* obj, const std::string key, AppProtect::ResourceStatus &ret)
{
    return true;
}

static bool QueryResourceFail_Stub(void* obj, const std::string key, AppProtect::ResourceStatus &ret)
{
    return false;
}

void NasReplicationServiceTest::SetUp()
{
    ControlDeviceInfo basicDeviceInfo;
    basicDeviceInfo.deviceName = "test";  // 文件系统名称在pair预处理过程中或者新创pair时会设置，此处不需要
    basicDeviceInfo.url = "";   // 使用安全IP登录，不需要IP和端口号
    basicDeviceInfo.port = "";  // 使用安全IP登录，不需要IP和端口号
    basicDeviceInfo.userName = "admin";
    basicDeviceInfo.password = "Huawei@123";
    basicDeviceInfo.poolId = 0;
    basicDeviceInfo.compress = false;
    basicDeviceInfo.dedup = false;
    basicDeviceInfo.poolId = 0;
    m_localController = std::make_unique<DoradoNas>(basicDeviceInfo, false);
    m_nasReplicationServiceObj = NasRepServiceObjOp::NasReplicationService::GetReplicationInstance("", "basic", 0);

    stub.set(sleep, returnVoid_Stub);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceSuc_Stub);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceSuc_Stub);
    stub.set(ADDR(HetroCommonService, DeleteResource), ReturnTrue_Stub);
    stub.set(ADDR(JobService, AddNewJob), returnVoid_Stub);
}

void NasReplicationServiceTest::TearDown()
{
}

void NasReplicationServiceTest::SetUpTestCase()
{
}

void NasReplicationServiceTest::TearDownTestCase()
{
}

static int QuerySuccess_Stub(void *obj, DeviceDetails &info)
{
    info.deviceName = "INVALID";
    return Module::SUCCESS;
}

static int QueryFail_Stub(void* obj, DeviceDetails &info)
{
    info.deviceName = "INVALID";
    return Module::FAILED;
}


/**
 * 用例名称：CheckReplicationPairInBasic_Success
 * 前置条件：无
 * check点：查询设备信息成功，并且remoteResName等于设备名称/查询设备信息失败
 */
TEST_F(NasReplicationServiceTest, CheckReplicationPairInBasic)
{
    ReplicationPairInfo replicationPairInfo;
    // status为Invalid,走异常分支
    replicationPairInfo.status = INVALIID;
    replicationPairInfo.remoteResName = "INVALID";
    bool result = m_nasReplicationServiceObj->CheckReplicatonPairInBaic(m_localController, replicationPairInfo);
    EXPECT_EQ(result, false);

    // 重置状态为normal
    replicationPairInfo.status = NORMAL;
    typedef int (*fptr)(DoradoNas*, DeviceDetails&);
    fptr DoradoNas_Query = (fptr)(&DoradoNas::Query);
    stub.set(DoradoNas_Query, QuerySuccess_Stub);
    result = m_nasReplicationServiceObj->CheckReplicatonPairInBaic(m_localController, replicationPairInfo);
    EXPECT_EQ(result, true);

    stub.set(DoradoNas_Query, QueryFail_Stub);
    result = m_nasReplicationServiceObj->CheckReplicatonPairInBaic(m_localController, replicationPairInfo);
    EXPECT_EQ(result, false);
    stub.reset(ADDR(DoradoNas, Query));
}

static NasRepServiceObjOp::NasReplicationServiceErrorCode CreateRemoteDeviceSuc_Stub(void* obj)
{
    return NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceNormal;
}

static NasRepServiceObjOp::NasReplicationServiceErrorCode CreateRemoteDeviceFail_Stub(void* obj)
{
    return NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceAbNormal;
}

static bool GetPairInfoInProductSuc_Stub(void* obj)
{
    return true;
}

static bool GetPairInfoInProductFail_Stub(void* obj)
{
    return false;
}

static bool GetPairInfoByIDSuc_Stub(void* obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
                                    ReplicationPairInfo& replicationPairInfo)
{
    replicationPairInfo.remoteResID = "123";
    return true;
}

static bool GetPairInfoByIDSuc1_Stub(void* obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
                                    ReplicationPairInfo& replicationPairInfo)
{
    replicationPairInfo.remoteResID = "basic";
    return true;
}

static bool GetPairInfoByIDFail_Stub(void* obj)
{
    return false;
}

static bool CheckReplicatonPairInBaicSuc_Stub(void* obj)
{
    return true;
}

static bool CheckReplicatonPairInBaicFail_Stub(void* obj)
{
    return false;
}

static bool UpdateReplicationPairBandWidthSuc_Stub(void* obj)
{
    return true;
}

static bool UpdateReplicationPairBandWidthFail_Stub(void* obj)
{
    return false;
}

/**
 * 用例名称：PrepareRemoteReplicatonPair_Pre
 * 前置条件：无
 * check点：查询设备信息成功，并且remoteResName等于设备名称/查询设备信息失败
 */
TEST_F(NasReplicationServiceTest, PrepareRemoteReplicatonPair_Pre)
{
    // 创建远程设备和端口组失败，走异常分支
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups),
            CreateRemoteDeviceFail_Stub);
    NasRepServiceObjOp::NasReplicationServiceErrorCode result =
    m_nasReplicationServiceObj->PrepareRemoteReplicatonPair(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceAbNormal);

    // 在产品中查询pair失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups),
            CreateRemoteDeviceSuc_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct),GetPairInfoInProductFail_Stub);
    result = m_nasReplicationServiceObj->PrepareRemoteReplicatonPair(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceNormal);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups));
}

/**
 * 用例名称：PrepareRemoteReplicatonPair_GetPairInfoById
 * 前置条件：无
 * check点：查询设备信息成功，并且remoteResName等于设备名称/查询设备信息失败
 */
TEST_F(NasReplicationServiceTest, PrepareRemoteReplicatonPair_GetPairInfoById)
{
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups),
            CreateRemoteDeviceSuc_Stub);
    // 在产品中查询pair成功但通过id查询pair信息失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct),GetPairInfoInProductSuc_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDFail_Stub);
    NasRepServiceObjOp::NasReplicationServiceErrorCode result = m_nasReplicationServiceObj->PrepareRemoteReplicatonPair(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceNormal);

    // 在产品中查询pair成功但通过id查询pair信息成功，m_basicFSID不等于远程资源ID
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc_Stub);
    result = m_nasReplicationServiceObj->PrepareRemoteReplicatonPair(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceAbNormal);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
}

/**
 * 用例名称：PrepareRemoteReplicatonPair_CheckReplicatonPairInBaic
 * 前置条件：无
 * check点：查询设备信息成功，并且remoteResName等于设备名称/查询设备信息失败
 */
// TEST_F(NasReplicationServiceTest, PrepareRemoteReplicatonPair_CheckReplicatonPairInBaic)
// {
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups),
//             CreateRemoteDeviceSuc_Stub);
//     // 在产品中查询pair成功但通过id查询pair信息失败
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct),GetPairInfoInProductSuc_Stub);
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc1_Stub);
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CheckReplicatonPairInBaic),
//             CheckReplicatonPairInBaicFail_Stub);
//     bool result = m_nasReplicationServiceObj->PrepareRemoteReplicatonPair(m_localController, m_localController);
//     EXPECT_EQ(result, false);

//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct));
//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups));
//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CheckReplicatonPairInBaic));
// }

/**
 * 用例名称：PrepareRemoteReplicatonPair_Next
 * 前置条件：无
 * check点：查询设备信息成功，并且remoteResName等于设备名称/查询设备信息失败
 */
// TEST_F(NasReplicationServiceTest, PrepareRemoteReplicatonPair_Next)
// {
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups),
//             CreateRemoteDeviceSuc_Stub);
//     // 在产品中查询pair成功但通过id查询pair信息失败
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct),GetPairInfoInProductSuc_Stub);
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc1_Stub);
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CheckReplicatonPairInBaic),
//             CheckReplicatonPairInBaicSuc_Stub);
//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, UpdateReplicationPairBandWidth),
//             UpdateReplicationPairBandWidthFail_Stub);
//     bool result = m_nasReplicationServiceObj->PrepareRemoteReplicatonPair(m_localController, m_localController);
//     EXPECT_EQ(result, false);

//     stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, UpdateReplicationPairBandWidth),
//             UpdateReplicationPairBandWidthSuc_Stub);
//     result = m_nasReplicationServiceObj->PrepareRemoteReplicatonPair(m_localController, m_localController);
//     EXPECT_EQ(result, true);

//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoInProduct));
//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAndBindRepPortGroups));
//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CheckReplicatonPairInBaic));
//     stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, UpdateReplicationPairBandWidth));
// }

static int UpdateReplicationSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int UpdateReplicationFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：UpdateReplicationPairBandWidth
 * 前置条件：无
 * check点：更新Replication带宽
 */
TEST_F(NasReplicationServiceTest, UpdateReplicationPairBandWidth)
{
    // pairID为空字符串，走成功逻辑
    std::string pairId = "";
    bool result = m_nasReplicationServiceObj->UpdateReplicationPairBandWidth(m_localController, pairId);
    EXPECT_EQ(result, true);

    pairId = "123";
    stub.set(ADDR(DoradoBlock, UpdateReplication), UpdateReplicationSuc_Stub);
    result = m_nasReplicationServiceObj->UpdateReplicationPairBandWidth(m_localController, pairId);
    EXPECT_EQ(result, true);

    stub.set(ADDR(DoradoBlock, UpdateReplication), UpdateReplicationFail_Stub);
    result = m_nasReplicationServiceObj->UpdateReplicationPairBandWidth(m_localController, pairId);
    EXPECT_EQ(result, false);

    stub.reset(ADDR(DoradoBlock, UpdateReplication));
}

/**
 * 用例名称：GetRemoteDeviceUserPwd
 * 前置条件：无
 * check点：获取远程设备用户名密码
 */
// TEST_F(NasReplicationServiceTest, GetRemoteDeviceUserPwd)
// {
//     std::string deviceUser = "";
//     // 查询resource失败
//     stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceFail_Stub);
//     bool result = m_nasReplicationServiceObj->GetRemoteDeviceUserPwd(deviceUser);
//     EXPECT_EQ(result, false);
//     stub.reset(ADDR(HetroCommonService, QueryResource));

//     // 查询resource成功，但ret.resource.resourceValue为空字符串
//     stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceSuc_Stub);
//     result = m_nasReplicationServiceObj->GetRemoteDeviceUserPwd(deviceUser);
//     EXPECT_EQ(result, false);
//     stub.reset(ADDR(HetroCommonService, QueryResource));
// }

static int QueryRemoteDeviceUserByNameSuc_Stub(void* obj, const std::string &userName, std::string &remoteDevUserID)
{
    return Module::SUCCESS;
}

static int DeleteRemoteDeviceUserByIDSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int DeleteRemoteDeviceUserByIDFail_Stub(void* obj, const std::string &remoteDevUserID)
{
    return Module::FAILED;
}

static int CreateRemoteDeviceUserSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int CreateRemoteDeviceUserFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：GetRemoteDeviceUserPwd
 * 前置条件：无
 * check点：获取远程设备用户名密码
 */
// TEST_F(NasReplicationServiceTest, CreateRemoteDeviceAdministrator)
// {
//     // 通过名称查询远程设备用户成功，但根据ID删除失败
//     stub.set(ADDR(DoradoNas, QueryRemoteDeviceUserByName), QueryRemoteDeviceUserByNameSuc_Stub);
//     stub.set(ADDR(DoradoNas, DeleteRemoteDeviceUserByID), DeleteRemoteDeviceUserByIDFail_Stub);
//     bool result = m_nasReplicationServiceObj->CreateRemoteDeviceAdministrator(m_localController);
//     EXPECT_EQ(result, false);

//     // 重置根据ID删除成功，但创建远程设备用户失败
//     stub.set(ADDR(DoradoNas, DeleteRemoteDeviceUserByID), DeleteRemoteDeviceUserByIDSuc_Stub);
//     stub.set(ADDR(DoradoNas, CreateRemoteDeviceUser), CreateRemoteDeviceUserFail_Stub);
//     result = m_nasReplicationServiceObj->CreateRemoteDeviceAdministrator(m_localController);
//     EXPECT_EQ(result, false);

//     // 重置创建远程设备用户成功
//     stub.set(ADDR(DoradoNas, CreateRemoteDeviceUser), CreateRemoteDeviceUserSuc_Stub);
//     result = m_nasReplicationServiceObj->CreateRemoteDeviceAdministrator(m_localController);
//     EXPECT_EQ(result, true);

//     stub.reset(ADDR(DoradoNas, QueryRemoteDeviceUserByName));
//     stub.reset(ADDR(DoradoNas, DeleteRemoteDeviceUserByID));
//     // stub.reset(ADDR(DoradoNas, CreateRemoteDeviceUser));
// }

static int GetLogicPortNameListSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int GetLogicPortNameListFail_Stub(void* obj)
{
    return Module::FAILED;
}

static int QueryReplicationPortIpInfoSuc_Stub(void* obj, std::vector<LogicalPorts> &ipList)
{
    LogicalPorts logicalPorts;
    logicalPorts.name = "test";
    logicalPorts.ipv4Address = "1.1.1.1";
    logicalPorts.ipv6Address = "2001:4860:4801:48::3";

    LogicalPorts logicalPort;
    logicalPort.name = "test1";
    logicalPort.ipv4Address = "";
    logicalPort.ipv6Address = "";
    ipList.push_back(logicalPort);
    ipList.push_back(logicalPorts);
    return Module::SUCCESS;
}

static int QueryReplicationPortIpInfoFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：GetLogicPortNameList
 * 前置条件：无
 * check点：获取逻辑端口名称列表
 */
TEST_F(NasReplicationServiceTest, GetLogicPortNameList)
{
    // 获取逻辑端口列表失败
    stub.set(ADDR(DoradoBlock, GetLogicPortNameList), GetLogicPortNameListFail_Stub);
    bool result = m_nasReplicationServiceObj->GetLogicPortNameList(m_localController, m_localController);
    EXPECT_EQ(result, false);

    // 重置获取逻辑端口列表成功，但查询端口IP信息失败
    stub.set(ADDR(DoradoBlock, GetLogicPortNameList), GetLogicPortNameListSuc_Stub);
    stub.set(ADDR(DoradoNas, QueryReplicationPortIpInfo), QueryReplicationPortIpInfoFail_Stub);
    result = m_nasReplicationServiceObj->GetLogicPortNameList(m_localController, m_localController);
    EXPECT_EQ(result, false);

    // 重置查询端口IP信息成功，且有数据
    stub.set(ADDR(DoradoNas, QueryReplicationPortIpInfo), QueryReplicationPortIpInfoSuc_Stub);
    result = m_nasReplicationServiceObj->GetLogicPortNameList(m_localController, m_localController);
    EXPECT_EQ(result, true);
    stub.reset(ADDR(DoradoBlock, GetLogicPortNameList));
    stub.reset(ADDR(DoradoNas, QueryReplicationPortIpInfo));
}

static int GetESNSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int GetESNFail_Stub(void* obj)
{
    return Module::FAILED;
}

static int CreateReplicationRepportgroupSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int CreateReplicationRepportgroupFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：GetLogicPortNameList
 * 前置条件：无
 * check点：获取逻辑端口名称列表
 */
TEST_F(NasReplicationServiceTest, CreateReplicationRepportgroup)
{
    std::string productGroupID = "123";
    std::string basicGroupID = "13";
    // 获取Esn失败
    stub.set(ADDR(DoradoNas, GetESN), GetESNFail_Stub);
    bool result = m_nasReplicationServiceObj->CreateReplicationRepportgroup(m_localController, m_localController,
                                                                            productGroupID, basicGroupID);
    EXPECT_EQ(result, false);

    // 重置获取Esn成功,但创建reportGroup组失败
    stub.set(ADDR(DoradoNas, GetESN), GetESNSuc_Stub);
    stub.set(ADDR(DoradoNas, CreateReplicationRepportgroup), CreateReplicationRepportgroupFail_Stub);
    result = m_nasReplicationServiceObj->CreateReplicationRepportgroup(m_localController, m_localController,
                                                                       productGroupID, basicGroupID);
    EXPECT_EQ(result, false);

    // 重置创建reportGroup组成功
    stub.set(ADDR(DoradoNas, CreateReplicationRepportgroup), CreateReplicationRepportgroupSuc_Stub);
    result = m_nasReplicationServiceObj->CreateReplicationRepportgroup(m_localController, m_localController,
                                                                       productGroupID, basicGroupID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(DoradoNas, CreateReplicationRepportgroup));
}

static int CreateRemoteDeviceSucInt_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int CreateRemoteDeviceFailInt_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：CreateRemoteDevice
 * 前置条件：无
 * check点：创建远程设备
 */
TEST_F(NasReplicationServiceTest, CreateRemoteDevice)
{
    // 预制m_productIscsiList数据
    m_nasReplicationServiceObj->m_productIscsiList.push_back("test1");
    m_nasReplicationServiceObj->m_basicIscsiIpList.push_back("test2");

    // createRemoteDevice失败
    stub.set((int(DoradoBlock::*)(std::string localPort, std::string remoteIP, std::string remoteUser,
            std::string remotePassWord, std::string &devicdID))
            ADDR(DoradoBlock, CreateRemoteDevice),CreateRemoteDeviceFailInt_Stub);
    bool result = m_nasReplicationServiceObj->CreateRemoteDevice(m_localController);
    EXPECT_EQ(result, false);

    // 重置创建remoteDevice成功
    stub.set((int(DoradoBlock::*)(std::string localPort, std::string remoteIP, std::string remoteUser,
        std::string remotePassWord, std::string &devicdID))
        ADDR(DoradoBlock, CreateRemoteDevice),CreateRemoteDeviceSucInt_Stub);
    result = m_nasReplicationServiceObj->CreateRemoteDevice(m_localController);
    EXPECT_EQ(result, true);
    stub.reset((int(DoradoBlock::*)(std::string localPort, std::string remoteIP, std::string remoteUser,
            std::string remotePassWord, std::string &devicdID))ADDR(DoradoBlock, CreateRemoteDevice));
}

static int RelinkRemoteDeviceSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int RelinkRemoteDeviceFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：RelinkRemoteDevice
 * 前置条件：无
 * check点：重连接远程设备
 */
TEST_F(NasReplicationServiceTest, RelinkRemoteDevice)
{
    // 预制m_productIscsiList数据
    m_nasReplicationServiceObj->m_productIscsiList.push_back("test1");
    m_nasReplicationServiceObj->m_basicIscsiIpList.push_back("test2");

    // RelinkRemoteDevice失败
    stub.set(ADDR(DoradoNas, RelinkRemoteDevice),RelinkRemoteDeviceFail_Stub);
    bool result = m_nasReplicationServiceObj->RelinkRemoteDevice(m_localController);
    EXPECT_EQ(result, false);

    // 重置创建RelinkRemoteDevice成功
    stub.set(ADDR(DoradoNas, RelinkRemoteDevice),RelinkRemoteDeviceSuc_Stub);
    result = m_nasReplicationServiceObj->RelinkRemoteDevice(m_localController);
    EXPECT_EQ(result, true);
    stub.reset(ADDR(DoradoNas, RelinkRemoteDevice));
}

static bool CreateRemoteDeviceMethodSuc_Stub(void* obj)
{
    return true;
}

static bool CreateRemoteDeviceMethodFail_Stub(void* obj)
{
    return false;
}

static bool CreateReplicationRepportgroupMethodSuc_Stub(void* obj)
{
    return true;
}

static bool CreateReplicationRepportgroupMethodFail_Stub(void* obj)
{
    return false;
}

static int BindRepportgroupsToRemoteDeviceSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int BindRepportgroupsToRemoteDeviceFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：RelinkRemoteDevice
 * 前置条件：无
 * check点：重连接远程设备
 */
TEST_F(NasReplicationServiceTest, CreateRemoteDeviceTaskInner)
{
    // 创建远程设备失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDevice), CreateRemoteDeviceMethodFail_Stub);
    bool result = m_nasReplicationServiceObj->CreateRemoteDeviceTaskInner(m_localController, m_localController);
    EXPECT_EQ(result, false);

    // 重置创建远程设备成功，但创建组失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDevice), CreateRemoteDeviceMethodSuc_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateReplicationRepportgroup),
             CreateReplicationRepportgroupMethodFail_Stub);
    result = m_nasReplicationServiceObj->CreateRemoteDeviceTaskInner(m_localController, m_localController);
    EXPECT_EQ(result, false);

    // 重置创建组成功，但将组合远程设备连接失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateReplicationRepportgroup),
        CreateReplicationRepportgroupMethodSuc_Stub);
    stub.set(ADDR(DoradoBlock, BindRepportgroupsToRemoteDevice),BindRepportgroupsToRemoteDeviceFail_Stub);
    result = m_nasReplicationServiceObj->CreateRemoteDeviceTaskInner(m_localController, m_localController);
    EXPECT_EQ(result, false);

    // 重置将组合远程设备连接成功
    stub.set(ADDR(DoradoBlock, BindRepportgroupsToRemoteDevice),BindRepportgroupsToRemoteDeviceSuc_Stub);
    result = m_nasReplicationServiceObj->CreateRemoteDeviceTaskInner(m_localController, m_localController);
    EXPECT_EQ(result, true);
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDevice));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateReplicationRepportgroup));
    stub.reset(ADDR(DoradoBlock, BindRepportgroupsToRemoteDevice));
}

/**
 * 用例名称：FirstCreateRemoteDeviceInfo
 * 前置条件：无
 * check点：重连接远程设备
 */
TEST_F(NasReplicationServiceTest, FirstCreateRemoteDeviceInfo)
{
    std::string basicEsn = "A1001";
    // getEsn失败
    stub.set(ADDR(DoradoNas, GetESN), GetESNFail_Stub);
    bool result = m_nasReplicationServiceObj->FirstCreateRemoteDeviceInfo(m_localController,m_localController,basicEsn);
    EXPECT_EQ(result, false);

    // 重置getEsn成功
    stub.set(ADDR(DoradoNas, GetESN), GetESNSuc_Stub);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceFail_Stub);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceFail_Stub);
    stub.set(ADDR(HetroCommonService, DeleteResource), ReturnTrue_Stub);
    stub.set((int(DoradoNas::*)(std::string esn, std::string &devicdID))ADDR(DoradoNas, BatchQueryRemoteDevice),
             BatchQueryRemoteDeviceSuc_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService,WaitRemoteDeviceNormal),
             WaitRemoteDeviceNormalMethodSuc_Stub);
    result = m_nasReplicationServiceObj->FirstCreateRemoteDeviceInfo(m_localController,m_localController,basicEsn);
    EXPECT_EQ(result, true);

    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService,WaitRemoteDeviceNormal),
            WaitRemoteDeviceNormalMethodFail_Stub);
    result = m_nasReplicationServiceObj->FirstCreateRemoteDeviceInfo(m_localController,m_localController,basicEsn);
    EXPECT_EQ(result, false);

    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService,WaitRemoteDeviceNormal));
}

static bool CreateRemoteDeviceTaskMethodSuc_Stub(void* obj)
{
    return true;
}

static bool CreateRemoteDeviceTaskMethodFail_Stub(void* obj)
{
    return false;
}

/**
 * 用例名称：FirstCreateRemoteDeviceInfo1
 * 前置条件：无
 * check点：重连接远程设备
 */
TEST_F(NasReplicationServiceTest, FirstCreateRemoteDeviceInfo1)
{
    std::string basicEsn = "A1001";
    stub.set(ADDR(DoradoNas, GetESN), GetESNSuc_Stub);
    stub.set(ADDR(HetroCommonService, QueryResource), QueryResourceFail_Stub);
    stub.set(ADDR(HetroCommonService, CreateResource), CreateResourceSuc_Stub);
    stub.set((int(DoradoNas::*)(std::string esn, std::string &devicdID))ADDR(DoradoNas, BatchQueryRemoteDevice),
             BatchQueryRemoteDeviceFail_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceTask),
             CreateRemoteDeviceTaskMethodFail_Stub);
    bool result = m_nasReplicationServiceObj->FirstCreateRemoteDeviceInfo(m_localController,m_localController,basicEsn);
    EXPECT_EQ(result, false);

    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceTask),
            CreateRemoteDeviceTaskMethodSuc_Stub);
    result = m_nasReplicationServiceObj->FirstCreateRemoteDeviceInfo(m_localController,m_localController,basicEsn);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(HetroCommonService, QueryResource));
    stub.reset(ADDR(HetroCommonService, CreateResource));
    stub.reset((int(DoradoNas::*)(std::string esn, std::string &devicdID))ADDR(DoradoNas, BatchQueryRemoteDevice));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService,CreateRemoteDeviceTask));
}

static bool CreateRemoteDeviceAdministratorMethodSuc_Stub(void* obj)
{
    return true;
}

static bool CreateRemoteDeviceAdministratorMethodFail_Stub(void* obj)
{
    return false;
}

static bool CreateRemoteDeviceTaskInnerMethodSuc_Stub(void* obj)
{
    return true;
}

static bool CreateRemoteDeviceTaskInnerMethodFail_Stub(void* obj)
{
    return false;
}

/**
 * 用例名称：CreateRemoteDeviceTask
 * 前置条件：无
 * check点：创建远程设备任务
 */
TEST_F(NasReplicationServiceTest, CreateRemoteDeviceTask)
{
    // 创建远程设备Administrator失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAdministrator),
        CreateRemoteDeviceAdministratorMethodFail_Stub);
    bool result = m_nasReplicationServiceObj->CreateRemoteDeviceTask(m_localController,m_localController);
    EXPECT_EQ(result, false);

    // 重置远程设备Administrator成功,但创建远程设备任务失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAdministrator),
        CreateRemoteDeviceAdministratorMethodSuc_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceTaskInner),
        CreateRemoteDeviceTaskInnerMethodFail_Stub);
    result = m_nasReplicationServiceObj->CreateRemoteDeviceTask(m_localController,m_localController);
    EXPECT_EQ(result, false);

    // 重置创建远程设备任务成功
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceTaskInner),
        CreateRemoteDeviceTaskInnerMethodSuc_Stub);
    result = m_nasReplicationServiceObj->CreateRemoteDeviceTask(m_localController,m_localController);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAdministrator));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceTaskInner));
}

static bool RelinkRemoteDeviceMethodSuc_Stub(void* obj)
{
    return true;
}

static bool RelinkRemoteDeviceMethodFail_Stub(void* obj)
{
    return false;
}

/**
 * 用例名称：CreateRemoteDeviceTask
 * 前置条件：无
 * check点：创建远程设备任务
 */
TEST_F(NasReplicationServiceTest, RecoverRemoteDeviceLink)
{
    // 远端设备状态正常
    int status = 1;
    bool result = m_nasReplicationServiceObj->RecoverRemoteDeviceLink(m_localController, m_localController,status);
    EXPECT_EQ(result, true);

    // 重置设备状态为故障
    status = 2;
    // 创建远程设备Administrator失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAdministrator),
            CreateRemoteDeviceAdministratorMethodFail_Stub);
    result = m_nasReplicationServiceObj->RecoverRemoteDeviceLink(m_localController, m_localController,status);
    EXPECT_EQ(result, false);


    // 重置远程设备Administrator成功,但重连接远程设备失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAdministrator),
            CreateRemoteDeviceAdministratorMethodSuc_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, RelinkRemoteDevice),
        RelinkRemoteDeviceMethodFail_Stub);
    result = m_nasReplicationServiceObj->RecoverRemoteDeviceLink(m_localController, m_localController,status);
    EXPECT_EQ(result, false);

    // 重置重连远程设备成功
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, RelinkRemoteDevice),
        RelinkRemoteDeviceMethodSuc_Stub);
    result = m_nasReplicationServiceObj->RecoverRemoteDeviceLink(m_localController, m_localController,status);
    EXPECT_EQ(result, false);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, CreateRemoteDeviceAdministrator));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, RelinkRemoteDevice));
}

static int GetReplicationPairIDSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int GetReplicationPairIDFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：GetPairInfoInProduct
 * 前置条件：无
 * check点：从产品中获取Pair信息
 */
TEST_F(NasReplicationServiceTest, GetPairInfoInProduct)
{
    // getEsn失败
    std:: string pairID = "1";
    stub.set(ADDR(DoradoNas, GetESN), GetESNFail_Stub);
    bool result = m_nasReplicationServiceObj->GetPairInfoInProduct(m_localController, m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重置getEsn成功,但获取复制信息失败
    stub.set(ADDR(DoradoNas, GetESN), GetESNSuc_Stub);
    stub.set(ADDR(DoradoNas, GetReplicationPairID), GetReplicationPairIDFail_Stub);
    result = m_nasReplicationServiceObj->GetPairInfoInProduct(m_localController,m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重置获取复制信息成功
    stub.set(ADDR(DoradoNas, GetReplicationPairID), GetReplicationPairIDSuc_Stub);
    result = m_nasReplicationServiceObj->GetPairInfoInProduct(m_localController,m_localController, pairID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(DoradoNas, GetReplicationPairID));
}

static int QueryRemoteDeviceSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int QueryRemoteDeviceFail_Stub(void* obj)
{
    return Module::FAILED;
}

static int AddReplicationRepportgroupMemberSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int AddReplicationRepportgroupMemberFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：AddLocalAndRemotePort
 * 前置条件：无
 * check点：添加本地及远程端口
 */
TEST_F(NasReplicationServiceTest, AddLocalAndRemotePort)
{
    // 查询远程设备失败
    std:: string basicDeviceID = "1";
    stub.set(ADDR(DoradoNas, QueryRemoteDevice), QueryRemoteDeviceFail_Stub);
    bool result = m_nasReplicationServiceObj->AddLocalAndRemotePort(m_localController, m_localController, basicDeviceID);
    EXPECT_EQ(result, false);

    // 重置查询远程设备成功,但AddReplicationRepportgroupMember失败
    stub.set(ADDR(DoradoNas, QueryRemoteDevice), QueryRemoteDeviceSuc_Stub);
    stub.set(ADDR(DoradoNas, AddReplicationRepportgroupMember), AddReplicationRepportgroupMemberFail_Stub);
    result = m_nasReplicationServiceObj->AddLocalAndRemotePort(m_localController, m_localController, basicDeviceID);
    EXPECT_EQ(result, false);

    // 重置AddReplicationRepportgroupMember成功
    stub.set(ADDR(DoradoNas, AddReplicationRepportgroupMember), AddReplicationRepportgroupMemberSuc_Stub);
    result = m_nasReplicationServiceObj->AddLocalAndRemotePort(m_localController, m_localController, basicDeviceID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(DoradoNas, QueryRemoteDevice));
    stub.reset(ADDR(DoradoNas, AddReplicationRepportgroupMember));
}

static bool GetLogicPortNameListMethodSuc_Stub(void* obj)
{
    return true;
}

static bool GetLogicPortNameListMethodFail_Stub(void* obj)
{
    return false;
}

static bool FirstCreateRemoteDeviceInfoMethodSuc_Stub(void* obj)
{
    return true;
}

static bool FirstCreateRemoteDeviceInfoMethodFail_Stub(void* obj)
{
    return false;
}

/**
 * 用例名称：CreateFail_GetLogicPortNameList
 * 前置条件：无
 * check点：创建远程设备及端口组
 */
TEST_F(NasReplicationServiceTest, CreateFail_GetLogicPortNameList)
{
    // 获取逻辑端口名称列表失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList),GetLogicPortNameListMethodFail_Stub);
    NasRepServiceObjOp::NasReplicationServiceErrorCode result = m_nasReplicationServiceObj->
            CreateRemoteDeviceAndBindRepPortGroups(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceAbNormal);
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList));
}

/**
 * 用例名称：CreateFail_GetEsn
 * 前置条件：无
 * check点：创建远程设备及端口组
 */
TEST_F(NasReplicationServiceTest, CreateFail_GetEsn)
{
    // 重置获取端口名称列表成功,但查询Esn失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList), GetLogicPortNameListMethodSuc_Stub);
    stub.set(ADDR(DoradoNas, GetESN), GetESNFail_Stub);
    NasRepServiceObjOp::NasReplicationServiceErrorCode result = m_nasReplicationServiceObj->
            CreateRemoteDeviceAndBindRepPortGroups(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceAbNormal);
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList));
    stub.reset(ADDR(DoradoNas, GetESN));
}

/**
 * 用例名称：CreateFail_FirstCreateRemoteDeviceInfo
 * 前置条件：无
 * check点：创建远程设备及端口组
 */
TEST_F(NasReplicationServiceTest, CreateFail_FirstCreateRemoteDeviceInfo)
{
    // 重置获取端口名称列表成功
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList), GetLogicPortNameListMethodSuc_Stub);
    // 重置查询Esn成功
    stub.set(ADDR(DoradoNas, GetESN), GetESNSuc_Stub);
    stub.set((int(DoradoNas::*)(std::string esn, std::string &devicdID,int &healthStatus,
            int &runStatus))ADDR(DoradoNas, BatchQueryRemoteDevice), BatchQueryRemoteDeviceFail_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, FirstCreateRemoteDeviceInfo),
            FirstCreateRemoteDeviceInfoMethodFail_Stub);
    NasRepServiceObjOp::NasReplicationServiceErrorCode result = m_nasReplicationServiceObj->
            CreateRemoteDeviceAndBindRepPortGroups(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceAbNormal);
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList));
    stub.reset((int(DoradoNas::*)(std::string esn, std::string &devicdID,int &healthStatus,
            int &runStatus))ADDR(DoradoNas, BatchQueryRemoteDevice));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, FirstCreateRemoteDeviceInfo));
}


/**
 * 用例名称：CreateSuc_FirstCreateRemoteDeviceInfo
 * 前置条件：无
 * check点：创建远程设备及端口组
 */
TEST_F(NasReplicationServiceTest, CreateSuc_FirstCreateRemoteDeviceInfo)
{
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList), GetLogicPortNameListMethodSuc_Stub);
    stub.set(ADDR(DoradoNas, GetESN), GetESNSuc_Stub);
    stub.set((int(DoradoNas::*)(std::string esn, std::string &devicdID,int &healthStatus,
            int &runStatus))ADDR(DoradoNas, BatchQueryRemoteDevice), BatchQueryRemoteDeviceFail_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, FirstCreateRemoteDeviceInfo),
        FirstCreateRemoteDeviceInfoMethodSuc_Stub);
    NasRepServiceObjOp::NasReplicationServiceErrorCode result = m_nasReplicationServiceObj->
            CreateRemoteDeviceAndBindRepPortGroups(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceNormal);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList));
    stub.reset((int(DoradoNas::*)(std::string esn, std::string &devicdID,int &healthStatus,
            int &runStatus))ADDR(DoradoNas, BatchQueryRemoteDevice));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, FirstCreateRemoteDeviceInfo));
}

static bool AddLocalAndRemotePortMethodSuc_Stub(void* obj)
{
    return true;
}

static bool AddLocalAndRemotePortMethodFail_Stub(void* obj)
{
    return false;
}

static bool RecoverRemoteDeviceLinkMethodSuc_Stub(void* obj)
{
    return true;
}

static bool RecoverRemoteDeviceLinkMethodFail_Stub(void* obj)
{
    return false;
}

/**
 * 用例名称：CreateRemoteDeviceAndBindRepPortGroups1
 * 前置条件：无
 * check点：创建远程设备及端口组
 */
TEST_F(NasReplicationServiceTest, CreateRemoteDeviceAndBindRepPortGroups1)
{
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList), GetLogicPortNameListMethodSuc_Stub);
    stub.set(ADDR(DoradoNas, GetESN), GetESNSuc_Stub);
    stub.set((int(DoradoNas::*)(std::string esn, std::string &devicdID,int &healthStatus,
            int &runStatus))ADDR(DoradoNas, BatchQueryRemoteDevice), BatchQueryRemoteDeviceSuc_Stub);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, AddLocalAndRemotePort),
             AddLocalAndRemotePortMethodFail_Stub);
    NasRepServiceObjOp::NasReplicationServiceErrorCode result = m_nasReplicationServiceObj->
            CreateRemoteDeviceAndBindRepPortGroups(m_localController, m_localController);
    EXPECT_EQ(result, NasRepServiceObjOp::NasReplicationServiceErrorCode::ReplicationServiceAbNormal);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetLogicPortNameList));
    stub.reset((int(DoradoNas::*)(std::string esn, std::string &devicdID,int &healthStatus,
            int &runStatus))ADDR(DoradoNas, BatchQueryRemoteDevice));
    stub.reset(ADDR(DoradoNas, GetESN));
    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, AddLocalAndRemotePort));
}

static int QueryReplicationSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int QueryReplicationFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：GetPairInfoByID
 * 前置条件：无
 * check点：通过ID查询信息
 */
TEST_F(NasReplicationServiceTest, GetPairInfoByID)
{
    // pairID为空字符串
    std:: string pairID = "";
    ReplicationPairInfo replicationPairInfo;
    bool result = m_nasReplicationServiceObj->GetPairInfoByID(m_localController, pairID, replicationPairInfo);
    EXPECT_EQ(result, false);

    pairID = "123";
    typedef int (*fptr)(DoradoNas*, ReplicationPairInfo&);
    fptr DoradoNas_QueryReplication = (fptr)(&DoradoNas::QueryReplication);
    stub.set(DoradoNas_QueryReplication, QueryReplicationFail_Stub);
    result = m_nasReplicationServiceObj->GetPairInfoByID(m_localController, pairID, replicationPairInfo);
    EXPECT_EQ(result, false);

    // 重置查询复制信息成功
    stub.set(DoradoNas_QueryReplication, QueryReplicationSuc_Stub);
    result = m_nasReplicationServiceObj->GetPairInfoByID(m_localController, pairID, replicationPairInfo);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(DoradoBlock, QueryReplication));
}

static int CreateSuc_Stub(void* obj, long long size)
{
    return Module::SUCCESS;
}

static int CreateFail_Stub(void* obj, long long size)
{
    return Module::FAILED;
}

static ssize_t Read_Stub_Neg1(int fd, void *buf, size_t count)
{
    return -1;
}

static ssize_t Read_Stub_1(int fd, void *buf, size_t count)
{
    return 1;
}

/**
 * 用例名称：CreateFileSystemInRemoteDevice
 * 前置条件：无
 * check点：在远程设备中创建文件系统
 */
TEST_F(NasReplicationServiceTest, CreateFileSystemInRemoteDevice)
{   
    stub.set(read, Read_Stub_Neg1);
    bool result = m_nasReplicationServiceObj->CreateFileSystemInRemoteDevice(m_localController, m_localController);
    EXPECT_EQ(result, false);
    stub.reset(read);

    typedef int (*fptr)(DoradoNas*, DeviceDetails&);
    fptr DoradoNas_Query = (fptr)(&DoradoNas::Query);
    stub.set(DoradoNas_Query, QueryFail_Stub);
    stub.set(read, Read_Stub_1);
    result = m_nasReplicationServiceObj->CreateFileSystemInRemoteDevice(m_localController, m_localController);
    EXPECT_EQ(result, false);
    stub.reset(DoradoNas_Query);

    // 重置查询成功
    stub.set(DoradoNas_Query, QuerySuccess_Stub);
    typedef int (*fptr2)(DoradoNas*, long long);
    fptr2 DoradoNas_Create = (fptr2)(&DoradoNas::Create);
    stub.set(DoradoNas_Create, CreateFail_Stub);
    result = m_nasReplicationServiceObj->CreateFileSystemInRemoteDevice(m_localController, m_localController);
    EXPECT_EQ(result, false);
    stub.reset(DoradoNas_Query);
    stub.reset(DoradoNas_Create);

    // 重置创建成功
    stub.set(DoradoNas_Query, QuerySuccess_Stub);
    stub.set(DoradoNas_Create, CreateSuc_Stub);
    result = m_nasReplicationServiceObj->CreateFileSystemInRemoteDevice(m_localController, m_localController);
    EXPECT_EQ(result, true);
    stub.reset(DoradoNas_Query);
    stub.reset(DoradoNas_Create);
    stub.reset(read);
}

static int DeleteSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int DeleteFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：DeleteFileSystemInRemoteDevice
 * 前置条件：无
 * check点：从远程设备删除文件系统
 */
TEST_F(NasReplicationServiceTest, DeleteFileSystemInRemoteDevice)
{
    typedef int (*fptr)(DoradoNas*);
    fptr DoradoNas_Delete = (fptr)(&DoradoNas::Delete);
    stub.set(DoradoNas_Delete, DeleteFail_Stub);
    EXPECT_NO_THROW(m_nasReplicationServiceObj->DeleteFileSystemInRemoteDevice(m_localController));

    stub.set(DoradoNas_Delete, DeleteSuc_Stub);
    EXPECT_NO_THROW(m_nasReplicationServiceObj->DeleteFileSystemInRemoteDevice(m_localController));
    stub.reset(ADDR(DoradoNas, Delete));
}


static int CreateReplicationSuc_Stub(void *obj, const int &fsId, const std::string &rDevId,const int &bandwidth,
                                     const std::string &snapTag, int &rfsId, std::string &pairId)
{
    return Module::SUCCESS;
}

static int CreateReplicationFail_Stub(void *obj, const int &fsId, const std::string &rDevId,const int &bandwidth,
                                      const std::string &snapTag, int &rfsId, std::string &pairId)
{
    return Module::FAILED;
}

TEST_F(NasReplicationServiceTest, CreateReplicationPair)
{
    std::string pairID;
    int remoteResId = 0;
    stub.set(ADDR(DoradoNas, CreateReplicationWithSnapTag), CreateReplicationFail_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->CreateReplicationPair(m_localController, 0, "", remoteResId, pairID),false);

    stub.set(ADDR(DoradoNas, CreateReplicationWithSnapTag), CreateReplicationSuc_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->CreateReplicationPair(m_localController, 0, "", remoteResId, pairID),true);
}

static bool GetPairInfoByIDSuc2_Stub(void* obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
                                     ReplicationPairInfo& replicationPairInfo)
{
    replicationPairInfo.status = INTERRUPTED;
    return true;
}

static bool GetPairInfoByIDSuc3_Stub(void* obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
                                     ReplicationPairInfo& replicationPairInfo)
{
    replicationPairInfo.status = SPLIT;
    replicationPairInfo.secresDataStatus = COMPLETE;
    return true;
}

static bool GetPairInfoByIDSuc4_Stub(void* obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
                                     ReplicationPairInfo& replicationPairInfo)
{
    replicationPairInfo.status = INVALIID;
    return true;
}

static bool GetPairInfoByIDSuc5_Stub(void* obj, std::shared_ptr<DoradoNas>& deviceController, const std::string& pairID,
                                     ReplicationPairInfo& replicationPairInfo)
{
    replicationPairInfo.status = NORMAL;
    return true;
}

static int ActiveReplicationSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int ActiveReplicationFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：ActiveReplicationPair
 * 前置条件：无
 * check点：从产品中获取Pair信息
 */
TEST_F(NasReplicationServiceTest, ActiveReplicationPair)
{
    // pairID为空字符串
    std:: string pairID = "";
    int64_t errorCode = 0;
    bool result = m_nasReplicationServiceObj->ActiveReplicationPair(m_localController, pairID, errorCode);
    EXPECT_EQ(result, false);

    // GetPairInfoByIDs失败
    pairID = "1";
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDFail_Stub);
    result = m_nasReplicationServiceObj->ActiveReplicationPair(m_localController, pairID, errorCode);
    EXPECT_EQ(result, false);

    // 重打桩，status为INTERRUPTED
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc2_Stub);
    result = m_nasReplicationServiceObj->ActiveReplicationPair(m_localController, pairID, errorCode);
    EXPECT_EQ(result, false);

    // 重打桩，status为SPILT
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc3_Stub);
    typedef int (*fptr2)(DoradoNas*, std::string);
    fptr2 DoradoNas_ActiveReplication= (fptr2)(&DoradoNas::ActiveReplication);
    stub.set(DoradoNas_ActiveReplication, ActiveReplicationFail_Stub);
    result = m_nasReplicationServiceObj->ActiveReplicationPair(m_localController, pairID, errorCode);
    EXPECT_EQ(result, false);

    stub.set(DoradoNas_ActiveReplication, ActiveReplicationSuc_Stub);
    result = m_nasReplicationServiceObj->ActiveReplicationPair(m_localController, pairID, errorCode);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(DoradoBlock, ActiveReplication));
}

static int SplitReplicationSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int SplitReplicationFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：SplitReplicationPair
 * 前置条件：无
 * check点：从产品中获取Pair信息
 */
TEST_F(NasReplicationServiceTest, SplitReplicationPair)
{
    // pairID为空字符串
    std:: string pairID = "";
    bool result = m_nasReplicationServiceObj->SplitReplicationPair(m_localController, pairID);
    EXPECT_EQ(result, true);

    // GetPairInfoByIDs失败
    pairID = "1";
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDFail_Stub);
    result = m_nasReplicationServiceObj->SplitReplicationPair(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为SPILT
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc3_Stub);
    result = m_nasReplicationServiceObj->SplitReplicationPair(m_localController, pairID);
    EXPECT_EQ(result, true);

    // 重打桩，status为Invalid
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc4_Stub);
    result = m_nasReplicationServiceObj->SplitReplicationPair(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为INTERRUPTED
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc2_Stub);
    typedef int (*fptr2)(DoradoNas*, std::string);
    fptr2 DoradoNas_SplitReplication= (fptr2)(&DoradoNas::SplitReplication);
    stub.set(DoradoNas_SplitReplication, SplitReplicationFail_Stub);
    result = m_nasReplicationServiceObj->SplitReplicationPair(m_localController, pairID);
    EXPECT_EQ(result, false);

    stub.set(DoradoNas_SplitReplication, SplitReplicationSuc_Stub);
    result = m_nasReplicationServiceObj->SplitReplicationPair(m_localController, pairID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(DoradoBlock, SplitReplication));
}

static int DeleteReplicationSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int DeleteReplicationFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：DeleteReplicatonPair
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, DeleteReplicatonPair)
{
    // pairID为空字符串
    std:: string pairID = "";
    bool result = m_nasReplicationServiceObj->DeleteReplicatonPair(m_localController, pairID);
    EXPECT_EQ(result, true);

    // GetPairInfoByIDs失败
    pairID = "1";
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDFail_Stub);
    result = m_nasReplicationServiceObj->DeleteReplicatonPair(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为NORMAL
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc5_Stub);
    result = m_nasReplicationServiceObj->DeleteReplicatonPair(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为SPILT
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc3_Stub);
    typedef int (*fptr2)(DoradoNas*, std::string);
    fptr2 DoradoNas_DeleteReplication= (fptr2)(&DoradoNas::DeleteReplication);
    stub.set(DoradoNas_DeleteReplication, DeleteReplicationFail_Stub);
    result = m_nasReplicationServiceObj->DeleteReplicatonPair(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重置删除成功
    stub.set(DoradoNas_DeleteReplication, DeleteReplicationSuc_Stub);
    result = m_nasReplicationServiceObj->DeleteReplicatonPair(m_localController, pairID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(DoradoBlock, DeleteReplication));
}

static int SecondaryResourceProtectEnableSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int SecondaryResourceProtectEnableFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：SecondaryResourceProtectEnable
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, SecondaryResourceProtectEnable)
{
    // pairID为空字符串
    std:: string pairID = "";
    bool result = m_nasReplicationServiceObj->SecondaryResourceProtectEnable(m_localController, pairID);
    EXPECT_EQ(result, true);

    // GetPairInfoByIDs失败
    pairID = "1";
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDFail_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectEnable(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为NORMAL
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc5_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectEnable(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为SPILT
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc3_Stub);
    typedef int (*fptr2)(DoradoNas*, std::string);
    fptr2 DoradoNas_SecondaryResourceProtectEnable= (fptr2)(&DoradoNas::SecondaryResourceProtectEnable);
    stub.set(DoradoNas_SecondaryResourceProtectEnable, SecondaryResourceProtectEnableFail_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectEnable(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重置删除成功
    stub.set(DoradoNas_SecondaryResourceProtectEnable, SecondaryResourceProtectEnableSuc_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectEnable(m_localController, pairID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(DoradoNas, SecondaryResourceProtectEnable));
}

static int SecondaryResourceProtectDisableSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int SecondaryResourceProtectDisableFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：SecondaryResourceProtectDisable
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, SecondaryResourceProtectDisable)
{
    // pairID为空字符串
    std:: string pairID = "";
    bool result = m_nasReplicationServiceObj->SecondaryResourceProtectDisable(m_localController, pairID);
    EXPECT_EQ(result, true);

    // GetPairInfoByIDs失败
    pairID = "1";
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDFail_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectDisable(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为NORMAL
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc5_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectDisable(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重打桩，status为SPILT
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc3_Stub);
    typedef int (*fptr2)(DoradoNas*, std::string);
    fptr2 DoradoNas_SecondaryResourceProtectDisable= (fptr2)(&DoradoNas::SecondaryResourceProtectDisable);
    stub.set(DoradoNas_SecondaryResourceProtectDisable, SecondaryResourceProtectDisableFail_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectDisable(m_localController, pairID);
    EXPECT_EQ(result, false);

    // 重置删除成功
    stub.set(DoradoNas_SecondaryResourceProtectDisable, SecondaryResourceProtectDisableSuc_Stub);
    result = m_nasReplicationServiceObj->SecondaryResourceProtectDisable(m_localController, pairID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(DoradoNas, SecondaryResourceProtectDisable));
}

static int SwitchOverPrimaryAndSecondResourceSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int SwitchOverPrimaryAndSecondResourceFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：SwitchOverFail_GetPairInfoByID
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, SwitchOverFail_GetPairInfoByID)
{
    std:: string pairID = "1";
    // GetPairInfoByIDs失败
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDFail_Stub);
    bool result = m_nasReplicationServiceObj->SwitchOverPrimaryAndSecondResource(m_localController, pairID);
    EXPECT_EQ(result, false);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
}

/**
 * 用例名称：SwitchOverFail_StatusNormal
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, SwitchOverFail_StatusNormal)
{
    std:: string pairID = "1";
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc5_Stub);
    bool result = m_nasReplicationServiceObj->SwitchOverPrimaryAndSecondResource(m_localController, pairID);
    EXPECT_EQ(result, false);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
}

/**
 * 用例名称：SwitchOverSuc_StatusSpilt
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, SwitchOverSuc_StatusSpilt)
{
    std:: string pairID = "1";
    typedef int (*fptr2)(DoradoNas*, std::string);
    fptr2 DoradoNas_SwitchOverPrimaryAndSecondResource= (fptr2)(&DoradoNas::SwitchOverPrimaryAndSecondResource);
    stub.set(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID),GetPairInfoByIDSuc3_Stub);
    stub.set(DoradoNas_SwitchOverPrimaryAndSecondResource, SwitchOverPrimaryAndSecondResourceSuc_Stub);
    bool result = m_nasReplicationServiceObj->SwitchOverPrimaryAndSecondResource(m_localController, pairID);
    EXPECT_EQ(result, true);

    stub.reset(ADDR(NasRepServiceObjOp::NasReplicationService, GetPairInfoByID));
    stub.reset(ADDR(DoradoNas, SwitchOverPrimaryAndSecondResource));
}

static int OpenPerformanceStatisticSwitchSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int OpenPerformanceStatisticSwitchFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：OpenPerformanceStatisticSwitch
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, OpenPerformanceStatisticSwitch)
{
    uint64_t speed = 0;
    stub.set(ADDR(DoradoNas, OpenPerformanceStatisticSwitch), OpenPerformanceStatisticSwitchFail_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->OpenPerformanceStatisticSwitch(m_localController), false);

    stub.set(ADDR(DoradoNas, OpenPerformanceStatisticSwitch), OpenPerformanceStatisticSwitchSuc_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->OpenPerformanceStatisticSwitch(m_localController), true);
    stub.reset(ADDR(DoradoNas, OpenPerformanceStatisticSwitch));
}

static int CreateSnapShotInStorageSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int CreateSnapShotInStorageFail_Stub(void* obj)
{
    return Module::FAILED;
}

/**
 * 用例名称：CreateSnapShotInStorage
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
TEST_F(NasReplicationServiceTest, CreateSnapShotInStorage)
{
    uint64_t speed = 0;
    std::string snapshotID = "";
    stub.set(ADDR(DoradoNas, CreateSnapshotWithSnapTag), CreateSnapShotInStorageFail_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->CreateSnapShotInStorage(m_localController, "", snapshotID), false);

    stub.set(ADDR(DoradoNas, CreateSnapshotWithSnapTag), CreateSnapShotInStorageSuc_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->CreateSnapShotInStorage(m_localController, "", snapshotID), true);
    stub.reset(ADDR(DoradoNas, CreateSnapshotWithSnapTag));
}

static int QuerySnapshotSuc_Stub(void* obj)
{
    return Module::SUCCESS;
}

static int QuerySnapshotFail_Stub(void* obj)
{
    return Module::FAILED;
}

static int DeleteSnapshotSuc_Stub(void* obj, std::string SnapshotName)
{
    return Module::SUCCESS;
}

static int DeleteSnapshotFail_Stub(void* obj, std::string SnapshotName)
{
    return Module::FAILED;
}

/**
 * 用例名称：DeleteSnapShotInStorage
 * 前置条件：无
 * check点：删除ReplicatonPair
 */
// TEST_F(NasReplicationServiceTest, DeleteSnapShotInStorage)
// {
//     std::string snapshotName = "";
//     bool result = m_nasReplicationServiceObj->DeleteSnapShotInStorage(m_localController, snapshotName);
//     EXPECT_EQ(result, true);

//     stub.set(ADDR(DoradoNas, QuerySnapshot), QuerySnapshotFail_Stub);
//     result = m_nasReplicationServiceObj->DeleteSnapShotInStorage(m_localController, snapshotName);
//     EXPECT_EQ(result, true);

//    stub.set(ADDR(DoradoNas, QuerySnapshot), QuerySnapshotSuc_Stub);
//    stub.set((int(DoradoNas::*)(std::string SnapshotName))ADDR(DoradoNas, DeleteSnapshot),DeleteSnapshotFail_Stub);
//    result = m_nasReplicationServiceObj->DeleteSnapShotInStorage(m_localController, snapshotName);
//    EXPECT_EQ(result, false);
//
//    stub.set((int(DoradoNas::*)(std::string SnapshotName))ADDR(DoradoNas, DeleteSnapshot),DeleteSnapshotSuc_Stub);
//    result = m_nasReplicationServiceObj->DeleteSnapShotInStorage(m_localController, snapshotName);
//    EXPECT_EQ(result, true);

    // stub.reset(ADDR(DoradoNas, QuerySnapshot));
//    stub.reset((int(DoradoNas::*)(std::string SnapshotName))ADDR(DoradoNas, DeleteSnapshot));
// }

static int RollBackBySnapShotIdSuc_Stub(void* obj, std::string SnapshotName)
{
    return Module::SUCCESS;
}

static int RollBackBySnapShotIdFail_Stub(void* obj, std::string SnapshotName)
{
    return Module::FAILED;
}

/**
 * 用例名称：RevertSnapShotInStorage
 * 前置条件：无
 * check点：从存储恢复快照
 */
TEST_F(NasReplicationServiceTest, RevertSnapShotInStorage)
{
    stub.set(ADDR(DoradoNas, RollBackBySnapShotId), RollBackBySnapShotIdFail_Stub);
    int64_t errorcode = 0;
    EXPECT_EQ(m_nasReplicationServiceObj->RevertSnapShotInStorage(m_localController, "", "", errorcode), false);

    stub.set(ADDR(DoradoNas, RollBackBySnapShotId), RollBackBySnapShotIdSuc_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->RevertSnapShotInStorage(m_localController, "", "", errorcode), true);

    stub.reset(ADDR(DoradoNas, RollBackBySnapShotId));
}

static int QuerySnapshotRollBackStatusSuc_Stub(void* obj, std::string SnapshotName)
{
    return Module::SUCCESS;
}

static int QuerySnapshotRollBackStatusFail_Stub(void* obj, std::string SnapshotName)
{
    return Module::FAILED;
}

/**
 * 用例名称：QueryRevertEndInfoInStorageFail_Query
 * 前置条件：无
 * check点：从存储恢复快照
 */
TEST_F(NasReplicationServiceTest, QueryRevertEndInfoInStorageFail_Query)
{
    std:: string snapshotId = "1";
    std:: string rollbackRate = "12";
    std:: string rollbackStatus = "2";
    std:: string endTime = "2";
    typedef int (*fptr)(DoradoNas*, DeviceDetails&);
    fptr DoradoNas_Query = (fptr)(&DoradoNas::Query);
    stub.set(DoradoNas_Query, QueryFail_Stub);
    int result = m_nasReplicationServiceObj->
            QueryRevertEndInfoInStorage(m_localController, rollbackRate, rollbackStatus,endTime, snapshotId);
    EXPECT_EQ(result, -1);
    stub.reset(ADDR(DoradoNas, Query));
}

static int QueryRevertInfoSuc_Stub(void* obj, std::string SnapshotName)
{
    return Module::SUCCESS;
}

static int QueryRevertInfoFail_Stub(void* obj, std::string SnapshotName)
{
    return Module::FAILED;
}

/**
 * 用例名称：QueryRevertInfoInStorage
 * 前置条件：无
 * check点：从存储恢复快照
 */
TEST_F(NasReplicationServiceTest, QueryRevertInfoInStorage)
{
    std::string rollbackRate = "";
    std::string rollbackStatus = "";
    int64_t errorCode = 0;
    typedef int (*fptr)(DoradoNas*, DeviceDetails&);
    fptr DoradoNas_Query = (fptr)(&DoradoNas::Query);
    stub.set(DoradoNas_Query, QueryFail_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->QueryRevertInfoInStorage(m_localController, rollbackRate,
            rollbackStatus, errorCode), false);
    stub.set(DoradoNas_Query, QuerySuccess_Stub);
    typedef int (*fptr2)(DoradoNas*, const std::string&, std::string&, std::string&);
    fptr2 DoradoNas_QueryRevertInfo = (fptr2)(&DoradoNas::QueryRevertInfo);
    stub.set(DoradoNas_QueryRevertInfo, QueryRevertInfoFail_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->QueryRevertInfoInStorage(m_localController, rollbackRate,
            rollbackStatus, errorCode), false);
    stub.set(DoradoNas_QueryRevertInfo, QueryRevertInfoSuc_Stub);
    EXPECT_EQ(m_nasReplicationServiceObj->QueryRevertInfoInStorage(m_localController, rollbackRate,
            rollbackStatus, errorCode), true);
    stub.reset(ADDR(DoradoNas, QueryRevertInfo));
    stub.reset(ADDR(DoradoNas, Query));
}
